package com.freespace.service;


import com.freespace.anno.RpcService;
import com.freespace.pojo.Product;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * product服务实现类
 * @author qq2946937384
 */
@RpcService
@Service
public class ProductServiceImpl implements IProductService {

    Map<Object, Product> productMap = new HashMap();

    @Override
    public Product getById(int id) {
        getAll();
        return productMap.get(id);
    }

    private void getAll() {
        if (productMap.size() == 0) {
            Product product1 = new Product();
            product1.setId(1);
            product1.setName("汽车");
            Product product2 = new Product();
            product2.setId(2);
            product2.setName("飞机");
            productMap.put(product1.getId(), product1);
            productMap.put(product2.getId(), product2);
        }
    }
}